<?php
session_start();
include('lib/lib.php');
include('connado.php');
//include('authen.php');
header("Content-type: text/html; charset=utf-8");
$logfile = PAHTLOG."ajax_cmdprovince-" . date("Y-m-d") . ".log";


$prov_id = $_REQUEST['prov_id'];
$prov_desc = $_REQUEST['prov_desc'];
$action = $_REQUEST['action'];

writelog($logfile, "province id     : " . $prov_id);
writelog($logfile, "province desc   : " . $prov_desc);
$prov_desc = iconv('tis-620', 'utf-8', $prov_desc);
writelog($logfile, "province desc   : " . $prov_desc);
writelog($logfile, "action   : " . $action);

if($action == "add"){
	$sql = "insert into province(province_id, province_desc)values(?, ?)";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($prov_id, $prov_desc);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "add province success!");
	}else{
		writelog($logfile, "add province error!");
	}
}else if($action == "del"){
	$sql = "delete from province where province_id=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($prov_id);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "delete province success!");
	}else{
		writelog($logfile, "delete province error!");
	}
}else if($action == "edit"){
	$sql = "update province set province_desc =? where province_id=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($prov_desc, $prov_id);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "update province success!");
	}else{
		writelog($logfile, "update province error!");
	}
	
}


writelog($logfile, "reply : OK");
writelog($logfile, "-------------------------------------------------- ");
echo viewProvince($db);

?>

